﻿package app.view.components.calendar 
{
	import com.snzflash.components.list.ListItemRenderer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * Рендер календаря
	 * @author firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class CalendarRendererBase extends ListItemRenderer
	{
		//import mx.binding.utils.BindingUtils;
		private var _state:String;
		
		
		//public var 
		//public var labelTxt:TextField;
		
		private var _view:CalendarRendererView;
		public function CalendarRendererBase() 
		{
			super();
			//trace(this);
		}
		
		override protected function init():void 
		{
			stop();
			super.init();
			mouseChildren = false;
			buttonMode = true;
			
			_view = new CalendarRendererView();
			addChild(_view);
		};
		
		//private function onOut(event:MouseEvent):void 
		//{
			//trace('onOut');
			//data.state = 'empty'
			//data = data;
		//};
		//
		//private function onOver(event:MouseEvent):void 
		//{
			//trace('onOver');
			//data.state = 'event';
			//data = data;
		//};
		
		//private function test(event:Event):void 
		//{
			//removeEventListener(Event.ADDED_TO_STAGE, test);
			//stage.addEventListener(MouseEvent.MOUSE_MOVE, changePosition);
		//};
		
		public function set label(value:String):void 
		{
			if (!value) value = '';
			_view.labelTxt.text = value;
		}
		
		//override public function destroy():void 
		//{
			//super.destroy();
		//};
		//[Bindable]
		override public function get data():Object { return super.data; };
		override public function set data(value:Object):void 
		{
			if ( !value ) return;			
			super.data = value;
			state = value.state;
			label = value.label;
		};
		
		override public function get enabled():Boolean { return super.enabled; };
		
		override public function set enabled(value:Boolean):void 
		{
			super.enabled = value;
			mouseEnabled = value;
		};
		
		public function get state():String { return _state; };
		
		
		//[Bindable]
		public function set state(value:String):void 
		{
			//trace('state : '  + value);
			_state = value;
			_view.visible = true;
			_view.gotoAndStop(value);
			_view.labelTxt.textColor = 0x989898
			switch (_state) 
			{
				case CalendarVO.EMPTY_STATE:
					_view.visible = false;
					enabled = false;
				break;
				
				case CalendarVO.EVENT_STATE:
					_view.labelTxt.textColor = 0x000000;
					enabled = true;
				break;
				
				case CalendarVO.NO_EVENT_STATE:
					_view.labelTxt.textColor = 0x989898;
					enabled = false;
				break;
			};
		};
	};
};